
import shutil
import os

import argparse
def parse():
    parser = argparse.ArgumentParser(description='模型迁移')
    parser.add_argument('--source', type=str, help='model_name：原名')
    parser.add_argument('--to'  , type=str, help='model_name：目的名')
    args = parser.parse_args()
    return args

import glob
def get_latest(model_name):
    path_model_s = glob.glob(f'checkpoints/{model_name}/{model_name}*.pth')
    path_model = max(path_model_s)
    return path_model



args = parse()
model_name_from = args.source
model_name_to = args.to

model_path_from = get_latest(model_name_from)
model_path_to = model_path_from.replace(model_name_from,model_name_to)

model_to_dir = os.path.dirname(model_path_to)
if not os.path.exists(model_to_dir):
    os.mkdir(model_to_dir)

shutil.copy(model_path_from,model_path_to)